<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>蜜读后台管理系统</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-2.2.0.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/md5.js"></script>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            font-family: "Microsoft YaHei";
        }

        body, .login_div, .login_div * {
            box-sizing: border-box;
            -moz-box-sizing: border-box; /*Firefox3.5+*/
            -webkit-box-sizing: border-box; /*Safari3.2+*/
            -o-box-sizing: border-box;
            /*Opera9.6*/
            -ms-box-sizing: border-box; /*IE8*/
        }

        input {
            outline: none;
        }

        button, .btn {
            border: none;
            display: inline-block;
            font-size: 12px;
            text-align: center;
            vertical-align: middle;
            cursor: pointer;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
            overflow: hidden;
        }

        button:active, .btn:active {
            -webkit-box-shadow: inset 0 8px 10px rgba(0, 0, 0, 0.1);
            box-shadow: inset 0 8px 10px rgba(0, 0, 0, 0.1);
        }

        button[disabled], html input[disabled] {
            cursor: not-allowed;
            opacity: 0.6;
            filter: alpha(opacity=60);
        }

        button[disabled]:active, button[disabled]:hover, html input[disabled]:active, html input[disabled]:hover {
            background-image: none;
            -webkit-box-shadow: none;
            box-shadow: none;
        }

        .login_div{
            width: 430px;
            height: 320px;
            /*height: 245px;*/
            position: absolute;
            z-index: 100;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            border-radius: 10px;
            -webkit-border-radius: 10px;
            -moz-border-radius: 10px;
            overflow: hidden;
            background: #00a2d4;
            -moz-box-shadow: 0px 2px 3px #333333;
            -webkit-box-shadow: 0px 2px 3px #333333;
            box-shadow: 0px 2px 3px #333333;
        }

        .login_name {
            text-align: center;
            margin-top: 30px;
        }

        .login_name input {
            width: 80%;
            border: 0;
            border-bottom: 2px solid #dddddd;
            height: 40px;
            padding-left: 10px;
            font-size: 16px;
            font-family: "Microsoft YaHei";
        }

        .login_name .input_div {
            height: 40px;
            float: left;
            width: 60%;
        }

        .login_name .yzm_img {
            height: 40px;
            float: left;
            width: 40%;
            overflow: hidden;
        }

        .login_name .input_div input {
            width: 98%;
            height: 40px;
            border: 0;
            border-bottom: 2px solid #DDDDDD;
        }

        .btnDiv {
            text-align: center;
            margin-top: 25px;
        }

        .btnDiv button {
            width: 80%;
            height: 40px;
            line-height: 40px;
            background: #66bd78;
            font-family: "Microsoft YaHei";
            font-size: 16px;
            color: white;
            text-align: center;
            border-radius: 8px;
            -webkit-border-radius: 8px;
            -moz-border-radius: 8px;
            display: inline-block;
            cursor: pointer;
        }

        .msg {
            text-align: center;
            color: red;
            font-size: 13px;
            height: 20px;
            line-height: 20px;
            margin-top: 10px;
        }

        @media (min-width: 320px) and (max-width: 768px) {
            .login_div{
                width: 80%;
                height: 245px;
                position: absolute;
                left: 0;
                top: 0;
                bottom: 0;
                right: 0;
                margin: auto;
                border-radius: 10px;
                -webkit-border-radius: 10px;
                -moz-border-radius: 10px;
                overflow: hidden;
                background: #fafbf6;
                -moz-box-shadow: 0px 2px 3px #333333;
                -webkit-box-shadow: 0px 2px 3px #333333;
                box-shadow: 0px 2px 3px #333333;
            }

            .login_name {
                text-align: center;
                margin-top: 10px;
            }

            .login_name input {
                width: 80%;
                border: 0;
                border-bottom: 2px solid #dddddd;
                height: 40px;
                padding-left: 10px;
                font-size: 14px;
                font-family: "Microsoft YaHei";
            }

            .btnDiv {
                text-align: center;
                margin-top: 20px;
            }

            .btnDiv div {
                width: 80%;
                height: 40px;
                line-height: 40px;
                background: #66bd78;
                font-size: 14px;
                font-family: "Microsoft YaHei";
                color: white;
                text-align: center;
                border-radius: 8px;
                -webkit-border-radius: 8px;
                -moz-border-radius: 8px;
                display: inline-block;
            }

            .msg {
                text-align: center;
                color: red;
                font-size: 12px;
                height: 20px;
                line-height: 20px;
                margin-top: 6px;
            }
        }
    </style>
    <script type="text/javascript">
        $(function () {

            //点击提交事件
            $("#submit").click(function () {
                login();
            });

            //回车提交事件
            document.onkeydown = function (e) {
                // 兼容FF和IE和Opera
                var theEvent = e || window.event;
                var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
                if (code === 13) {//keyCode=13是回车键
                    login();
                }
            };
        });

        //刷新验证码
        function reloadValidateCode() {
            var url = "/login/getCaptcha?date=" + new Date().getTime();
            $('#captchaImg').attr('src',url);
        }

        /**
         * 登录操作
         * @returns {boolean}
         */
        function login() {
            var uname = $("#uname").val();
            var pwd = $("#pwd").val();
            var code = $("#code").val();
            if (uname === "") {
                $(".msg").text("用户名为空");
                $("#uname").focus();
                return false;
            } else if (pwd === "") {
                $(".msg").text("密码为空");
                $("#pwd").focus();
                return false;
            } else if (code === "") {
                $(".msg").text("验证码为空");
                $("#code").focus();
                return false;
            } else {
                //MD5加密
                //$("#pwd").val(hex_md5(pwd));
                $.ajax({
                    url: "/login/login",
                    type: "post",
                    data: $("#form1").serialize(),
                    dataType: "json",
                    success: function (data) {
                        if (data.status === 1) {
                            reloadValidateCode();
                            $(".msg").text(data.message);
                        } else {
                            location.href = "/login/success";
                        }
                    },
                    error: function (data) {
                        $(".msg").text(data.message);
                    }
                });
            }
        }
    </script>
</head>
<body style="background-color: #e3e7ec">
<div class="login_div">
    <form id="form1">
        <div class="login_name">
            <input type="text" id="uname" name="account" placeholder="请输入用户名"/>
        </div>
        <div class="login_name">
            <input type="password" id="pwd" name="password" placeholder="请输入密码"/>
        </div>
        <div class="login_name">
            <div style="overflow: hidden;width: 80%;display: inline-block;">
                <div class="input_div">
                    <input type="text" id="code" name="captcha" placeholder="请输入验证码"/>
                </div>
                <div class="yzm_img">
                    <img style="width: 100%;height: 100%;" id="captchaImg" onclick="reloadValidateCode();"
                         src="/login/getCaptcha" align="absmiddle"/>
                    <input type="hidden" id="ValidateCodeNum" value=""/>
                </div>
            </div>
        </div>
    </form>
    <div class="btnDiv">
        <button class="btn" id="submit" type="submit">登&nbsp;&nbsp;&nbsp;录</button>
    </div>
    <div class="msg"></div>
</div>
</body>
</html>